﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using Dev_house_Project.DataAccessLayer.EntityDataModel;
using Dev_house_Project.Providers.DataProviders;
using Dev_house_Project.Providers.SynchronizationProviders;
using Microsoft.Synchronization.Data;

namespace Dev_house_project.ServiceHoster
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DataService
    {
        /// <summary>
        /// Retreive data from local data cache.
        /// </summary>
        /// <returns>Collection of <see cref="Company"/> objects</returns>
        [OperationContract]
        public List<Company> GetDataFromLocalStorage()
        {
            var dataProvider = new CompanyDataProvider(Configurator.LocalConnectionString);
            return dataProvider.GetAllCompanies();
        }

        /// <summary>
        /// Provides saving modified data into local data cache.
        /// </summary>
        /// <param name="dataList">Collection of <see cref="Company"/> objects</param>
        [OperationContract]
        public void SubmitChangesToLocalStorage(List<Company> dataList)
        {
            var dataProvider = new CompanyDataProvider(Configurator.LocalConnectionString);
            dataProvider.SaveCompanies(dataList);
        }

        /// <summary>
        /// Retreive data from remote server.
        /// </summary>
        /// <returns>Collection of <see cref="Company"/> objects</returns>
        [OperationContract]
        public List<Company> GetDataFromRemoteStorage()
        {
            var dataProvider = new CompanyDataProvider(Configurator.RemoteConnectionString);
            return dataProvider.GetAllCompanies();
        }

        /// <summary>
        /// Provides saving modified data into remote database.
        /// </summary>
        /// <param name="dataList">Collection of <see cref="Company"/> objects</param>
        [OperationContract]
        public void SubmitChangesToRemoteStorage(List<Company> dataList)
        {
            var dataProvider = new CompanyDataProvider(Configurator.RemoteConnectionString);
            dataProvider.SaveCompanies(dataList);
        }

        /// <summary>
        /// Provides synchronization between local cache and remote data storage.
        /// </summary>
        [OperationContract]
        public void Synchronize()
        {
            //LocalCacheSyncAgent agent = new LocalCacheSyncAgent();            
            //SyncStatistics stat =  agent.Synchronize();

        }
    }
}
